<template>
  <el-card>
    <div slot="header">
      <div class="category-header">
        <span>销售额分类占比</span>
        <el-radio-group v-model="value" size="mini">
          <el-radio-button label="全部渠道"></el-radio-button>
          <el-radio-button label="线上"></el-radio-button>
          <el-radio-button label="门店"></el-radio-button>
        </el-radio-group>
      </div>
    </div>
    <div>
      <div class="charts" ref="charts"></div>
    </div>
  </el-card>
</template>

<script>
import echarts from 'echarts' //1引入
export default {
  data() {
    return {
      value: '全部渠道',
    }
  },
  mounted() {
    let mychart = echarts.init(this.$refs.charts)
    mychart.setOption({
      title: {
        text: '视频',
        subtext: '1048',
        left: 'center',
        top: 'center',
      },
      tooltip: {
        trigger: 'item',
      },
      series: [
        {
          name: 'Access From',
          type: 'pie',
          radius: ['40%', '70%'],
          avoidLabelOverlap: false,
          itemStyle: {
            borderRadius: 10,
            borderColor: '#fff',
            borderWidth: 2,
          },
          label: {
            show: true,
            position: 'outsize',
          },
          labelLine: {
            show: true,
          },
          data: [
            { value: 1048, name: '搜索引擎:1048' },
            { value: 735, name: '直接访问:735' },
            { value: 580, name: '邮件营销:580' },
            { value: 484, name: '联盟广告 :484' },
            { value: 300, name: '视频广告:300' },
          ],
        },
      ],
    })
    // 图表绑定事件
    mychart.on('mouseover', (params) => {
      //   console.log(params)
      const { name, value } = params.data
      mychart.setOption({
        title: {
          text: name,
          subtext: value,
        },
      })
    })
  },
}
</script>

<style scoped>
.category-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.header {
  border-bottom: 1px solid #eee;
  padding: 10px 20px;
}
.charts {
  width: 100%;
  height: 300px;
}
</style>
